from bs4 import BeautifulSoup

soup = BeautifulSoup('<html>data</html>', 'lxml')
# 会自动补全html格式
print(soup)

#  find 方法 :搜索文档树

# 准备文档字符串
html = '''<head>

    <link rel="stylesheet" href="//assets.dxycdn.com/gitrepo/ncov-mobile/dist/umi.bundle.css?t=1600243759374">

    <meta charset="utf-8">
    <meta content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover" name="viewport">
    <meta content="#000000" name="theme-color">
    <title>全球新冠病毒最新实时疫情地图_丁香园</title>
    <script>
        window.routerBase = "/ncovh5/view";
    </script>
<script charset="utf-8" src="//assets.dxycdn.com/gitrepo/ncov-mobile/dist/vendors~p__ECommerce~p__Pneumonia~p__Pneumonia__area~p__Pneumonia__area__index_en~p__Pneumonia__inde~72c6853e.async.8f722d73.js"></script><script charset="utf-8" src="//assets.dxycdn.com/gitrepo/ncov-mobile/dist/vendors~p__ECommerce~p__Pneumonia~p__Pneumonia__area~p__Pneumonia__area__index_en~p__Pneumonia__inde~5d7fcaba.async.8ed919a9.js"></script><link rel="stylesheet" type="text/css" href="//assets.dxycdn.com/gitrepo/ncov-mobile/dist/vendors~p__Pneumonia~p__Pneumonia__area~p__Pneumonia__area__index_en~p__Pneumonia__index_en.async.9f1a94c3.css"><script charset="utf-8" src="//assets.dxycdn.com/gitrepo/ncov-mobile/dist/vendors~p__Pneumonia~p__Pneumonia__area~p__Pneumonia__area__index_en~p__Pneumonia__index_en.async.d7bb3e3e.js"></script><script charset="utf-8" src="//assets.dxycdn.com/gitrepo/ncov-mobile/dist/vendors~p__ECommerce~p__Pneumonia~p__Pneumonia__index_en.async.4985eaf5.js"></script><link rel="stylesheet" type="text/css" href="//assets.dxycdn.com/gitrepo/ncov-mobile/dist/p__Pneumonia.async.2314bdfc.css"><script charset="utf-8" src="//assets.dxycdn.com/gitrepo/ncov-mobile/dist/p__Pneumonia.async.a16c273a.js"></script><meta name="description" content="丁香园、丁香医生整合各权威渠道发布的官方数据，通过疫情地图直观展示，持续更新最新的新型冠状病毒肺炎的实时疫情动态。"><meta name="keywords" content="最新疫情、实时疫情、疫情地图、疫情、丁香园"><meta name="baidu-site-verification" content="IL1HU7F7Vj"><meta name="description" content="丁香园、丁香医生整合各权威渠道发布的官方数据，通过疫情地图直观展示，持续更新最新的新型冠状病毒肺炎的实时疫情动态。"><meta name="keywords" content="最新疫情、实时疫情、疫情地图、疫情、丁香园"><meta name="baidu-site-verification" content="IL1HU7F7Vj"></head>
'''

# 创建BeautifulSoup对象
soup1 = BeautifulSoup(html, 'lxml')

# 查找标签

data_script = soup1.find("script")
print("查找script标签:", data_script)
data_title = soup1.find("title")
print("查找title标签:", data_title)
data_str = soup1.find(text="全球新冠病毒最新实时疫情地图_丁香园")
print(data_str)

# tag对象
print(type(data_title))
print(type(data_script))
# String对象
print(type(data_str))

# tag对象的三个属性  name:标签名称
#  attrs:获取标签所有属性的键和值
#  text:获取标签的文本字符串

print("标签名称:", data_title.name)
print("标签所有属性:", data_title.attrs)
print("标签文本内容:", data_title.text)

